﻿-- =============================================
-- Script Template
-- =============================================


use CrmContacto
update Contacto
set TipoDocumentoId = null
delete from TipoDocumento

if  exists (select 1 from sys.objects where name = 'FK_TipoDocumento_Empresa' and parent_object_id = object_id('TipoDocumento'))
begin
alter table TipoDocumento drop constraint FK_TipoDocumento_Empresa
end 

GO
if  exists (select 1 from sys.objects where name = 'DF__TipoDocum__Empre__531856C7' and parent_object_id = object_id('TipoDocumento'))
begin

alter table TipoDocumento DROP CONSTRAINT DF__TipoDocum__Empre__531856C7
end
GO
if  exists (select 1 from sys.columns where name = 'EmpresaId' and object_id = object_id('TipoDocumento'))
begin
alter table TipoDocumento drop column EmpresaId 
end

GO


if not exists (select 1 from sys.columns where name = 'PaisId' and object_id = object_id('TipoDocumento'))
begin
alter table TipoDocumento add PaisId int null
end

GO

if not exists (select 1 from sys.objects where name = 'FK_TipoDocumento_Pais' and parent_object_id = object_id('TipoDocumento'))
begin
alter table TipoDocumento add constraint FK_TipoDocumento_Pais foreign key (PaisId) references Pais(Id)
end 